﻿@model KPIS.GERP.Models.ICM.PrePurchaseRequestItem

<div id="loadingPanel" style="z-index: 10000000;">
    <div class="loading"></div>
    <div id="textloding" style="color: red; text-align: center; font-size: x-large; position:fixed; bottom: 30px; width: 100%;"></div>
</div>

@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit") { @Html.HiddenFor(model => model.PprItemId)   }
    @Html.HiddenFor(model => model.PprId)
    @Html.HiddenFor(model => model.BgSourceId)
    @Html.HiddenFor(model => model.BgExpId)
    @Html.HiddenFor(model => model.RegularId)
    @Html.HiddenFor(model => model.CreatedBy)
    @Html.HiddenFor(model => model.CreatedWhen)
    @Html.HiddenFor(model => model.UpdatedBy)
    @Html.HiddenFor(model => model.UpdatedWhen)
    @*@Html.HiddenFor(model => model.RegularId, new { id="hRegularId" })
    @Html.HiddenFor(model => model.BgSourceId, new { id="hBgSourceId" })
    @Html.HiddenFor(model => model.BgExpId, new { id="hBgExpId" })*@
          @{ var ModelPrePurchase = (PrePurchaseRequest)ViewBag.ModelPrePurchase; var serviceProjectOperation = new KPIS.GERP.WEB.GIMS.ProjectOperationService.ProjectOperationServiceClient(); var serviceResource = new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient(); var newList = new List<SelectListItem>(); var newItem = new SelectListItem() { Value = "", Text = "" }; newList.Add(newItem); bool bEdit = ViewContext.RouteData.Values["action"].ToString().ToLower() == "edit"; }<div class="clearfix">
    <div class="row-fluid">
        <div class="span6"><h4 class="text-info">เลือกรายการที่ต้องการ @ViewBag.PcTypeName</h4></div>
        <div class="span6"><h4 class="text-error pull-right">@ViewBag.YearTypeName @ViewBag.BgYear</h4></div>
    </div>
    <div class="row-fluid">
        <div class="control-group">
            <div class="control-label">
                อนุมัติโครงการ
            </div>
            <div class="controls">
                @{
                    var projectOperationSelectList = serviceProjectOperation.SelectList(new KPIS.GERP.Models.BGM.ProjectOperation
                        {
                            RecordStatus = KPIS.GERP.Models.SYS.RecordStatus.ApprovedStatus
                            ,
                            BgYear = ViewBag.BgYear
                            //, JobSiteId = ModelPrePurchase.RequestJobSiteId
                        }, KPIS.GERP.WEB.GIMS.Class.GimsMembership.CurrentEmpId);
                }
                @Html.DropDownListFor(m => m.ProjectOperationExpense.ProjOperId, projectOperationSelectList, new { id = "ddlProjOperId", @class = "chzn-select input-xlarge", data_manualwidth = "95%", data_placeholder = "เลือกอนุมัติโครงการ...", style = "display: none;" })<br />
                <span class="text-info" style="font-style:italic">(โครงการตามหน่วยงานของท่าน)</span>
                @Html.ValidationMessageFor(model => model.ProjectOperationExpense.ProjOperId)
            </div>
        </div>
        <div class="control-group">
            <div class="control-label">
                ค่าใช้จ่าย
            </div>
            <div class="controls">
                @Html.DropDownListFor(m => m.ProjOperExpId
                , (bEdit ? (IEnumerable<SelectListItem>)serviceProjectOperation.SelectListExpense(
                    new KPIS.GERP.Models.BGM.ProjectOperationExpense() { ProjOperId = Model.ProjectOperationExpense.ProjOperId.Value, RecordStatus = "!" + RecordStatus.DeletedStatus }) : (IEnumerable<SelectListItem>)newList)
                                  , new { id = "ddlProjOperExpId", @class = "input-xlarge", size = "5", style = "width:95%; height: 200px" })
                @Html.ValidationMessageFor(model => model.ProjOperExpId)
            </div>
        </div>

        <hr />

        @*@if (ModelPrePurchase.PcTypeId != 1)
            {*@
        <div class="control-group">
            <div class="control-label">
                ระบุพัสดุที่ซื้อ/จ้างทำ
            </div>
            <div class="controls">
                @Html.RadioButtonFor(m => m.HaveItem, true, new { onclick = "ShowResource(true)" })<span class="lbl"> ระบุ</span>&nbsp;&nbsp;&nbsp;&nbsp;
                @Html.RadioButtonFor(m => m.HaveItem, false, new { onclick = "ShowResource(false)" })<span class="lbl" style="width:100px"> ไม่ระบุ</span>
                @Html.ValidationMessageFor(model => model.HaveItem)
            </div>
        </div>
        @*}
            else
            {
                @Html.HiddenFor(m => m.HaveItem)
            }*@

        <div id="Resource" style="display:none;">

            <div class="control-group">
                <div class="control-label">
                    ประเภทพัสดุ
                </div>
                <div class="controls">
                    @Html.TextBoxFor(m => m.MasResourceItem.MasResourceSubGroup.MasResourceGroup.MasResourceType.Name, new { id = "lblResTypeName", @readonly = "true", style = "color: #669fc7" })
                    @*<input id="lblResTypeName" type="text" readonly="true" style="color: #669fc7" />*@
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    หมวดพัสดุ
                </div>
                <div class="controls">
                    @Html.TextBoxFor(m => m.MasResourceItem.MasResourceSubGroup.MasResourceGroup.Name, new { id = "lblResGrpName", @readonly = "true", style = "color: #669fc7" })
                    @*<input id="lblResGrpName" type="text" readonly="true" style="color: #669fc7" />*@
                    @{
                        List<SelectListItem> item1 = null;
                        if ((bEdit && (Model.HaveItem ?? true)))
                        {
                            var criteriaModel = new KPIS.GERP.Models.ICM.MasResourceGroup()
                                {
                                    ResTypeId = Model.MasResourceItem.MasResourceSubGroup.MasResourceGroup.ResTypeId.Value,
                                    RecordStatus = "!" + RecordStatus.DeletedStatus
                                };
                            var mrsg = serviceResource.SelectListResourceGroup(criteriaModel).ToList();
                            item1 = mrsg;
                        }
                        else
                        {

                            item1 = newList;
                        }
                    }
                    @Html.DropDownListFor(m => m.MasResourceItem.MasResourceSubGroup.ResGrpId
                    , item1
                    , new { id = "ddlResGrpId", @class = "chzn-select", data_manualwidth = "95%", data_placeholder = "เลือกหมวดพัสดุ...", style = "display: none;" })
                    @Html.ValidationMessageFor(model => model.MasResourceItem.MasResourceSubGroup.ResGrpId)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    กลุ่มพัสดุ
                </div>
                <div class="controls">
                    @Html.TextBoxFor(m => m.MasResourceItem.MasResourceSubGroup.Name, new { id = "lblResSubGrpName", @readonly = "true", style = "color: #669fc7" })
                    @*<input id="lblResSubGrpName" type="text" readonly="true" style="color: #669fc7" />*@
                    @Html.DropDownListFor(m => m.MasResourceItem.ResSubGrpId
                    , (bEdit && (Model.HaveItem ?? true) ? serviceResource.SelectListResourceSubGroup(new KPIS.GERP.Models.ICM.MasResourceSubGroup() { ResGrpId = Model.MasResourceItem.MasResourceSubGroup.ResGrpId.Value, RecordStatus = "!" + RecordStatus.DeletedStatus }).ToList() : newList)
                             , new { id = "ddlResSubGrpId", @class = "chzn-select input-xlarge", data_manualwidth = "95%", data_placeholder = "เลือกกลุ่มพัสดุ...", style = "display: none;" })
                    @Html.ValidationMessageFor(model => model.MasResourceItem.ResSubGrpId)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    รายการพัสดุ
                </div>
                <div class="controls">
                    @Html.TextBoxFor(m => m.MasResourceItem.Name, new { id = "lblResItemName", @readonly = "true", style = "color: #669fc7" })
                    @Html.HiddenFor(m => m.ResItemId, new { id = "lblResItemId" })
                    @*<input id="lblResItemName" type="text" readonly="true" style="color: #669fc7" />
                        <input id="lblResItemId" type="hidden" />*@
                    @Html.DropDownListFor(m => m.ResItemId
                    , (bEdit && (Model.HaveItem ?? true) ? (IEnumerable<SelectListItem>)serviceResource.SelectListResourceItem(new KPIS.GERP.Models.ICM.MasResourceItem() { ResSubGrpId = Model.MasResourceItem.ResSubGrpId.Value, RecordStatus = "!" + RecordStatus.DeletedStatus }).ToList() : (IEnumerable<SelectListItem>)newList)
                                      , new { id = "ddlResItemId", @class = "input-xlarge", style = "width:95%; height: 200px", size = "5" })
                    @Html.ValidationMessageFor(model => model.ResItemId)
                </div>
            </div>

            <hr />
        </div>

        <div id="Amount" style="display:none;">
            <div class="control-group">
                <div class="control-label">
                    รายละเอียด
                </div>
                <div class="controls">
                    @Html.TextAreaFor(model => model.Descr, new { id = "lblDescr", @class = "input-xlarge", style = "width:95%; text-align:left; width:550px; height:120px;" })
                    @Html.ValidationMessageFor(model => model.Descr)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    จำนวน
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.Qty, new { id = "lblQty", @class = "input-xlarge", style = "background-color: yellow;width:120px" })
                    @Html.TextBoxFor(m => m.MasResourceItem.MasUnit.Name, new { id = "lblUnitName", @readonly = "true", style = "color: #669fc7" })
                    @*<input id="lblUnitName" type="text" readonly="true" style="color: #669fc7" />*@
                    @Html.ValidationMessageFor(model => model.Qty)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    ราคาแนะนำต่อหน่วย
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.StdPrice, 
                new { id = "lblStdPrice", style = "width:120px; text-align:right;" }) บาท
                    @Html.ValidationMessageFor(model => model.StdPrice)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    ราคาต่อหน่วย
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.Price, 
                         new { id = "lblPrice", style = "width:120px; text-align:right; background-color: yellow;" }) บาท
                    @Html.ValidationMessageFor(model => model.Price)
                </div>
            </div>
            <div class="control-group">
                <div class="control-label">
                    รวมราคา
                </div>
                <div class="controls">
                    @Html.TextBoxFor(model => model.Amount, 
                         new { id = "lblAmount", style = "width:120px; text-align:right; background-color: yellow;" }) บาท
                    @Html.ValidationMessageFor(model => model.Amount)
                </div>
            </div>
        </div>
    </div>
</div> 
<style type="text/css"> 
    /* Absolute Center CSS Spinner */
    .loading {
        position: fixed;
        z-index: 999;
        height: 2em;
        width: 2em;
        overflow: show;
        margin: auto;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
    }

    /* Transparent Overlay */
    .loading:before {
        content: '';
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.3);
    }

    /* :not(:required) hides these rules from IE9 and below */
    .loading:not(:required) {
        /* hide "loading..." text */
        font: 0/0 a;
        color: transparent;
        text-shadow: none;
        background-color: transparent;
        border: 0;
    }

    .loading:not(:required):after {
        content: '';
        display: block;
        font-size: 10px;
        width: 1em;
        height: 1em;
        margin-top: -0.5em;
        -webkit-animation: spinner 1500ms infinite linear;
        -moz-animation: spinner 1500ms infinite linear;
        -ms-animation: spinner 1500ms infinite linear;
        -o-animation: spinner 1500ms infinite linear;
        animation: spinner 1500ms infinite linear;
        border-radius: 0.5em;
        -webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
        box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
    }

    /* Animation */
    @Html.Raw("@")-webkit-keyframes spinner {
        0% {
            -webkit-transform: rotate(0deg);
            -moz-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            -o-transform: rotate(0deg);
            transform: rotate(0deg);
        }

        100% {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
        }
    }

    @Html.Raw("@")-moz-keyframes spinner {
        0% {
            -webkit-transform: rotate(0deg);
            -moz-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            -o-transform: rotate(0deg);
            transform: rotate(0deg);
        }

        100% {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
        }
    }

    @Html.Raw("@")-o-keyframes spinner {
        0% {
            -webkit-transform: rotate(0deg);
            -moz-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            -o-transform: rotate(0deg);
            transform: rotate(0deg);
        }

        100% {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
        }
    }

    @Html.Raw("@")keyframes spinner {
        0% {
            -webkit-transform: rotate(0deg);
            -moz-transform: rotate(0deg);
            -ms-transform: rotate(0deg);
            -o-transform: rotate(0deg);
            transform: rotate(0deg);
        }

        100% {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
        }
    }

</style>

@*Loading&#8230;*@

@{
    ViewBag.ProjOperId = Model == null || Model.ProjectOperationExpense == null ? 0 : Model.ProjectOperationExpense.ProjOperId;
}
@Html.Partial("_PrePurchaseItemScript")
